package Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.UserDAO;
import bean.User;

public class UserSelectServlet extends HttpServlet {
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");

		int id = Integer.parseInt(request.getParameter("id"));
		//int id = 1;
		User user = new UserDAO().get(id);

		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("<table align='center' border='1' cellspacing='0'>\r\n");
		stringBuffer.append("<tr><td>id</td><td>username</td><td>password</td></tr>\r\n");
		String trForamt = "<tr><td>%d</td><td>%s</td><td>%s</td></tr>\r\n";

		String tr = String.format(trForamt, user.getId(), user.getUsername(), user.getPassword());
		stringBuffer.append(tr);

		stringBuffer.append("</table>");
		response.getWriter().write(stringBuffer.toString());

	}
}
